// leaveDate_package/pages/teacherLeaveDate/teacherLeaveDate.ts
import {getLeaveDetail,postTeacherCheck} from '../../../api/teacher/notice'
Page({

  /**
   * 页面的初始数据
   */
  data: {
   leaveStuInfo:{
   },
   formData:{
    leaveId: 0,
    leaveStatu: "",
    remark: ""
   },
   rule:{
    props:"remark",
    ruleVal:[{
      type:"requierd",
      tooltip:"备注不能为空",
    }]
  }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(data:any) {
  const {leaveId} = data
  this.reqLeaveDetail(leaveId)
  },
  // 查看请假调课历史记录
  toSeeHistory(){
 wx.navigateTo({
   url:"/leaveDate_package/pages/teacherLeaveDateRecord/teacherLeaveDateRecord"
 })
  },
  // 获取请假历史记录
  async reqLeaveDetail(leaveId:number){
    const {code,data:res} = await getLeaveDetail({
      leaveId
    })
    if(code === 200){
     this.setData({
      leaveStuInfo:res
     })
    }
  },
  // 输入款输入内容
  handelChange(e:any){
    const remark = e.detail.value
    const formData = this.data.formData
    formData.remark = remark
    this.setData({
      formData
    })
  },
  cnacel(){
  wx.navigateBack()
  },
  async submit(){
    const leaveStuInfo = this.data.leaveStuInfo as any
    const formData = this.data.formData
    if(!formData.remark) return wx.Utils.toast("备注不能为空!")
    formData.leaveId = leaveStuInfo.leaveId
    formData.leaveStatu = "2"
    console.log(formData);
   const {code,data:res,msg} =  await postTeacherCheck(formData)
   if(code === 200){
    if(res){
      wx.Utils.toast("提交成功!")
      wx.navigateBack()
    }
   }else{
     wx.Utils.toast(msg)
   }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})